﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.PublicOfficialSelectionService;
using org.in2bits.MyXls;

namespace CommunitySystem
{
    public partial class ChengJi_MianShiControl_XDJL : UserControl
    {
        private int ExamID = -1;
        private PublicOfficialSelectionService.PublicOfficialSelectionServiceClient Client1 =
            new PublicOfficialSelectionService.PublicOfficialSelectionServiceClient();
        private ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel> selectedempmodel =
           new ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel>();
        private int Nian = 0;
        IList<PublicOfficialInfo> poi = new List<PublicOfficialInfo>();
        public ChengJi_MianShiControl_XDJL()
        {
            InitializeComponent();
            //for (int i = DateTime.Today.Year; i > DateTime.Today.Year - 10; i--)
            //{
            //    ComboBoxItem cbi = new ComboBoxItem();
            //    cbi.Content = i.ToString();
            //    cbi.Tag = i;
            //    nian.Items.Add(cbi);
            //}
            //nian.SelectedIndex = 0;
            Client1.GetPublicOfficialInfo1Completed += new EventHandler<GetPublicOfficialInfo1CompletedEventArgs>(Client1_GetPublicOfficialInfo1Completed);
            Client1.GetPublicOfficialInfo1Async(1, 0);
            //Load();
        }
        void Client1_GetPublicOfficialInfo1Completed(object sender, GetPublicOfficialInfo1CompletedEventArgs e)
        {
            biaoti.ItemsSource = null;
            poi =e.Result.Where(p=>p.Type==1).ToList();
            ObservableCollection<PublicOfficialInfo> poi1 = new ObservableCollection<PublicOfficialInfo>();
            //if (poi.Where(p => p.Status != 3).FirstOrDefault() != null) poi1.Add(poi.Where(p => p.Status != 3).FirstOrDefault());
            foreach (PublicOfficialInfo p in poi)
            {
               // if (p.Status == 1 || p.Status == 0) poi1.Add(p);
                if (!p.IsLocked.Value) poi1.Add(p);
            }
            if (poi1.Count > 0 && poi1[0] != null)
            {
                biaoti.ItemsSource = poi1;
                if (poi1.Count > 0) biaoti.SelectedIndex = 0;
            }
            Load();
        }
        void gangwei_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (((ComboBox)sender).SelectedItem != null)
                ExamID = ((CommunitySystem.PublicOfficialSelectionService.PublicOfficialInfo)((((ComboBox)sender).SelectedItem))).ID;
            else ExamID = 0;
        }
        public void Load()
        {
            Client1.GetFenShuPublicOfficialRecordbyEmpIDCompleted += new EventHandler<PublicOfficialSelectionService.GetFenShuPublicOfficialRecordbyEmpIDCompletedEventArgs>(Client1_GetFenShuPublicOfficialRecordbyEmpIDCompleted);
            Client1.GetFenShuPublicOfficialRecordbyEmpIDAsync("面试", ExamID, "选调交流", islock);
        }

        void Client1_GetFenShuPublicOfficialRecordbyEmpIDCompleted(object sender, PublicOfficialSelectionService.GetFenShuPublicOfficialRecordbyEmpIDCompletedEventArgs e)
        {
            ObservableCollection<PublicOfficialRecordModel> temp =
                (ObservableCollection<PublicOfficialRecordModel>)e.Result;
            List<string> tempstring = new List<string>();
            if (temp != null && temp.Count > 0)
            {
                for (int i = 0; i < temp.Count; i++)
                {
                    if (!tempstring.Contains(temp[i].Unit + "-" + temp[i].Department + "-" + temp[i].Duty))
                        tempstring.Add(temp[i].Unit + "-" + temp[i].Department + "-" + temp[i].Duty);

                }
                for (int i = 0; i < tempstring.Count; i++)
                {
                    for(int n=0;n<temp.Where(p=>p.Unit == tempstring[i].Split('-')[0] &&
                                                                        p.Department == tempstring[i].Split('-')[1] &&
                                                                        p.Duty == tempstring[i].Split('-')[2]).Count();n++)
                    {
                        temp.Where(p => p.Unit == tempstring[i].Split('-')[0] &&
                                        p.Department == tempstring[i].Split('-')[1] &&
                                        p.Duty == tempstring[i].Split('-')[2]).ToList()[n].MingCi = n + 1;
                    }
                }
            }

            for (int i = 0; i < temp.Count; i++)
            {
                temp[i].Sec = i + 1;
            }
            DGRole.ItemsSource = null;
            DGRole.ItemsSource = temp;
        }


        private string islock = "0";
        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            biaoti.ItemsSource = null;
            islock = "1";
            ObservableCollection<PublicOfficialInfo> poi1 = new ObservableCollection<PublicOfficialInfo>();
            foreach (PublicOfficialInfo i in poi)
            {
                //if (i.Status == 3) poi1.Add(i);
                if (i.IsLocked.Value) poi1.Add(i);
            }
            if (poi1.Count > 0 && poi1[0] != null)
            {
                biaoti.ItemsSource = poi1;
                if (poi1.Count > 0) biaoti.SelectedIndex = 0;
            }
            Load();
        }

        private void chkHiddenCols_Unchecked(object sender, RoutedEventArgs e)
        {
            biaoti.ItemsSource = null;
            islock = "0";
            ObservableCollection<PublicOfficialInfo> poi1 = new ObservableCollection<PublicOfficialInfo>();
            //if (poi.Where(p => p.Status != 3).FirstOrDefault() != null) poi1.Add(poi.Where(p => p.Status != 3).FirstOrDefault());
            foreach (PublicOfficialInfo p in poi)
            {
               //if (p.Status == 1 || p.Status == 0) poi1.Add(p);
                if (!p.IsLocked.Value) poi1.Add(p);
            }
            if (poi1.Count > 0 && poi1[0] != null)
            {
                biaoti.ItemsSource = poi1;
                if (poi1.Count > 0) biaoti.SelectedIndex = 0;
            }
            else
            {
                biaoti.ItemsSource = null;
                ExamID = -1;
            }
            Load();
        }

        private void Data_Click(object sender, RoutedEventArgs e)
        {
            //var seljw = this.DGRole.SelectedItem as PublicOfficialRecordModel;
            //if (seljw != null)
            //{
            //    ChengJiWindow RMWindow = new ChengJiWindow(Convert.ToInt32(seljw.PublicOfficialRecordID), false);
            //    RMWindow.Closed += new EventHandler(RMWindow_Closed);
            //    RMWindow.Show();

            //}
            //else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要编辑的人员！");

            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel>)DGRole.ItemsSource)
                {
                    if (i.IsLocked == true)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("该职位已锁定，不可编辑！");
                        return;
                    }
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                if (selectedempmodel.Count > 1)
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("只能选择一个人员进行成绩编辑！");
                    return;
                }
                ChengJiWindow RMWindow = new ChengJiWindow(Convert.ToInt32(selectedempmodel[0].PublicOfficialRecordID), false);
                RMWindow.Closed += new EventHandler(RMWindow_Closed);
                RMWindow.Show();


            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要编辑的人员！");
        }
        void RMWindow_Closed(object sender, EventArgs e)
        {
            Load();
        }

        private void CheXiao_Click(object sender, RoutedEventArgs e)
        {
            //var seljw = this.DGRole.SelectedItem as PublicOfficialRecordModel;
            //if (seljw != null)
            //{
            //    Client1.CheXiaoMianShiCompleted += new EventHandler<CheXiaoMianShiCompletedEventArgs>(Client1_CheXiaoMianShiCompleted);
            //    Client1.CheXiaoMianShiAsync(seljw.ID, seljw.PublicOfficialRecordID);
            //}
            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel>)DGRole.ItemsSource)
                {
                    if (i.IsLocked == true)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("该职位已锁定，不可撤销！");
                        return;
                    }
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                if (MessageBox.Show("确定撤销面试吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    ObservableCollection<int> ids = new ObservableCollection<int>();

                    foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in selectedempmodel)
                    {
                        ids.Add(i.PublicOfficialRecordID);
                    }
                    Client1.CheXiaoMianShiCompleted -=
                        new EventHandler<CheXiaoMianShiCompletedEventArgs>(Client1_CheXiaoMianShiCompleted);
                    Client1.CheXiaoMianShiCompleted +=
                        new EventHandler<CheXiaoMianShiCompletedEventArgs>(Client1_CheXiaoMianShiCompleted);
                    Client1.CheXiaoMianShiAsync(ids);
                }
            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要撤销面试的人员！");
        }

        void Client1_CheXiaoMianShiCompleted(object sender, CheXiaoMianShiCompletedEventArgs e)
        {
            if (e.Result == true)
            {
                SilverlightMessageBoxLibrary.Message.InfoMessage("撤销成功!");
                Load();
            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("该人员已经生成面试成绩，不可撤销！");
        }


        private void ChaData_Click(object sender, RoutedEventArgs e)
        {
            Load();
        }

        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            foreach (PublicOfficialSelectionService.PublicOfficialRecordModel p in DGRole.ItemsSource)
            {
                p.IsSelected = (bool)cb.IsChecked;
                //CheckBox cb1 = DGRole.Columns[0].GetCellContent(p) as CheckBox;
                //cb1.IsChecked = p.IsSelected;
                if (p.IsSelected)
                {
                    if (selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(p);
                    }
                }
                else
                {
                    if (selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault() != null)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(i => i.ID == p.ID).FirstOrDefault());
                    }
                }
            }

        }

        private void nitongyi_Click(object sender, RoutedEventArgs e)
        {
            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel>)DGRole.ItemsSource)
                {
                    if (i.IsLocked == true)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("该职位已锁定！");
                        return;
                    }
                    //if(i.MianShiScore <= 0)
                    //{
                    //    SilverlightMessageBoxLibrary.Message.ErrorMessage("所选人员还有未输入面试成绩，不可拟同意！");
                    //    return;
                    //}
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                if (MessageBox.Show("确定要拟同意所选人员吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    ObservableCollection<int> ids = new ObservableCollection<int>();

                    foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in selectedempmodel)
                    {
                        ids.Add(i.PublicOfficialRecordID);
                    }
                    Client1.NiTongYiorNotCompleted -= new EventHandler<NiTongYiorNotCompletedEventArgs>(Client1_NiTongYiorNotCompleted);
                    Client1.NiTongYiorNotCompleted += new EventHandler<NiTongYiorNotCompletedEventArgs>(Client1_NiTongYiorNotCompleted);
                    Client1.NiTongYiorNotAsync(ids, "拟同意");
                }
            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要拟同意的人员！");
        }

        private void butongyi_Click(object sender, RoutedEventArgs e)
        {
            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel>)DGRole.ItemsSource)
                {
                    if (i.IsLocked == true)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("该职位已锁定！");
                        return;
                    }
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                if (MessageBox.Show("确定要不同意所选人员吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    ObservableCollection<int> ids = new ObservableCollection<int>();

                    foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in selectedempmodel)
                    {
                        ids.Add(i.PublicOfficialRecordID);
                    }
                    Client1.NiTongYiorNotCompleted -= new EventHandler<NiTongYiorNotCompletedEventArgs>(Client1_NiTongYiorNotCompleted);
                    Client1.NiTongYiorNotCompleted += new EventHandler<NiTongYiorNotCompletedEventArgs>(Client1_NiTongYiorNotCompleted);
                    Client1.NiTongYiorNotAsync(ids, "不同意");
                }
            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要不同意的人员！");
        }

        void Client1_NiTongYiorNotCompleted(object sender, NiTongYiorNotCompletedEventArgs e)
        {
            if (e.Result == true)
            {
                SilverlightMessageBoxLibrary.Message.InfoMessage("成功!");
                Load();
            }
        }

        private void fangqi_Click(object sender, RoutedEventArgs e)
        {
            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel>)DGRole.ItemsSource)
                {
                    if (i.IsLocked == true)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("该职位已锁定！");
                        return;
                    }
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                if (MessageBox.Show("确定要放弃所选人员吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    ObservableCollection<int> ids = new ObservableCollection<int>();

                    foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in selectedempmodel)
                    {
                        ids.Add(i.PublicOfficialRecordID);
                    }
                    Client1.NiTongYiorNotCompleted -= new EventHandler<NiTongYiorNotCompletedEventArgs>(Client1_NiTongYiorNotCompleted);
                    Client1.NiTongYiorNotCompleted += new EventHandler<NiTongYiorNotCompletedEventArgs>(Client1_NiTongYiorNotCompleted);
                    Client1.NiTongYiorNotAsync(ids, "放弃");
                }
            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要放弃的人员！");
        }


        private void SaveData_Click(object sender, RoutedEventArgs e)
        {
            selectedempmodel.Clear();
            if (DGRole.ItemsSource != null)
            {
                foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in (ObservableCollection<PublicOfficialSelectionService.PublicOfficialRecordModel>)DGRole.ItemsSource)
                {
                    if (i.IsSelected == true && selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() == null)
                    {
                        selectedempmodel.Add(i);
                    }
                    if (selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault() != null && i.IsSelected == false)
                    {
                        selectedempmodel.Remove(selectedempmodel.Where(p => p.ID == i.ID).FirstOrDefault());
                    }
                }
            }
            if (selectedempmodel.Count > 0)
            {
                string ids = "";

                foreach (PublicOfficialSelectionService.PublicOfficialRecordModel i in selectedempmodel)
                {
                    ids += i.ID.ToString() + ",";
                }
                var downLoad = new SaveFileDialog()
                                   {
                                       //Filter = "Excel files(2007~2010) (*.xlsx)|*.xlsx|Excel files(2003) (*.xls)|*.xls", //"Excel files (*.xlsx)|*.xlsx|(*.xls)|*.xls",
                                       Filter = "Excel files(2003) (*.xls)|*.xls",
                                   };
                if (downLoad.ShowDialog() == true)
                {
                    DataSheetExport = downLoad.OpenFile();
                    Client1.GetPublicOfficialRecordbyEmpIDForDaoChuCompleted -=
                        new EventHandler<GetPublicOfficialRecordbyEmpIDForDaoChuCompletedEventArgs>(
                            Client1_GetPublicOfficialRecordbyEmpIDForDaoChuCompleted);
                    Client1.GetPublicOfficialRecordbyEmpIDForDaoChuCompleted +=
                        new EventHandler<GetPublicOfficialRecordbyEmpIDForDaoChuCompletedEventArgs>(
                            Client1_GetPublicOfficialRecordbyEmpIDForDaoChuCompleted);
                    Client1.GetPublicOfficialRecordbyEmpIDForDaoChuAsync("(" + ids.Substring(0, ids.Length - 1) + ")", "面试");
                }
            }
            else
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("没有数据可以导出！");
            }
        }

        private ObservableCollection<PublicOfficialRecordModel> temp =
            new ObservableCollection<PublicOfficialRecordModel>();
        private Stream DataSheetExport = null;
        void Client1_GetPublicOfficialRecordbyEmpIDForDaoChuCompleted(object sender, GetPublicOfficialRecordbyEmpIDForDaoChuCompletedEventArgs e)
        {
            temp = e.Result;

            XlsDocument xls = new XlsDocument();
            XF xf = xls.NewXF();
            xf.UseBorder = true;
            xf.HorizontalAlignment = HorizontalAlignments.Centered;
            xf.VerticalAlignment = VerticalAlignments.Centered;
            xf.TopLineStyle = 1;
            xf.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf.BottomLineStyle = 1;
            xf.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf.LeftLineStyle = 1;
            xf.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf.RightLineStyle = 1;
            xf.RightLineColor = org.in2bits.MyXls.Colors.Black;

            XF xf1 = xls.NewXF();
            xf1.UseBorder = true;
            xf1.TopLineStyle = 1;
            xf1.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.BottomLineStyle = 1;
            xf1.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.LeftLineStyle = 1;
            xf1.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.RightLineStyle = 1;
            xf1.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf1.HorizontalAlignment = HorizontalAlignments.Centered;
            xf1.VerticalAlignment = VerticalAlignments.Centered;
            xf1.Font.Bold = true;
            xf1.Font.Height = 15 * 20;

            XF xf3 = xls.NewXF();
            xf3.UseBorder = true;
            xf3.TopLineStyle = 1;
            xf3.TopLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.BottomLineStyle = 1;
            xf3.BottomLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.LeftLineStyle = 1;
            xf3.LeftLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.RightLineStyle = 1;
            xf3.RightLineColor = org.in2bits.MyXls.Colors.Black;
            xf3.HorizontalAlignment = HorizontalAlignments.Centered;
            xf3.VerticalAlignment = VerticalAlignments.Centered;
            xf3.Font.Bold = true;
            xf3.Font.Height = 12 * 20;

            Worksheet sheet = xls.Workbook.Worksheets.AddNamed("面试成绩汇总表");
            sheet.Cells.Merge(1, 1, 1, 10);
            sheet.Cells.Add(1, 1, "徐汇区" + Convert.ToDateTime(temp[0].ExameDate).Year + "年科级及以下公务员选调交流面试结果汇总表", xf1);
            sheet.Cells.Add(2, 1, "序号", xf3);
            sheet.Cells.Add(2, 2, "名次", xf3);
            sheet.Cells.Add(2, 3, "姓名", xf3);
            sheet.Cells.Add(2, 4, "证件号码", xf3);
            sheet.Cells.Add(2, 5, "报名单位", xf3);
            sheet.Cells.Add(2, 6, "报名职务", xf3);
            sheet.Cells.Add(2, 7, "面试分数", xf3);
            sheet.Cells.Add(2, 8, "考生总分", xf3);
            sheet.Cells.Add(2, 9, "现职务", xf3);
            sheet.Cells.Add(2, 10, "备注", xf3);
            ColumnInfo colInfo = new ColumnInfo(xls, sheet);
            sheet.AddColumnInfo(colInfo);
            ColumnInfo colInfo2 = new ColumnInfo(xls, sheet);
            colInfo2.Width = 15 * 256;
            colInfo2.ColumnIndexStart = 2;
            colInfo2.ColumnIndexEnd = 2;
            sheet.AddColumnInfo(colInfo2);

            ColumnInfo colInfo9 = new ColumnInfo(xls, sheet);
            colInfo9.Width = 30 * 256;
            colInfo9.ColumnIndexStart = 3;
            colInfo9.ColumnIndexEnd = 3;
            sheet.AddColumnInfo(colInfo9);

            ColumnInfo colInfo10 = new ColumnInfo(xls, sheet);
            colInfo10.Width = 20 * 256;
            colInfo10.ColumnIndexStart = 4;
            colInfo10.ColumnIndexEnd = 4;
            sheet.AddColumnInfo(colInfo10);

            if (temp.Count > 0)
            {
                for (int i = 0; i < temp.Count; i++)
                {
                    sheet.Cells.Add(i + 3, 1, (i + 1).ToString(), xf);
                    if (temp[i].MingCi != null) sheet.Cells.Add(i + 3, 2, temp[i].MingCi.ToString(), xf); else sheet.Cells.Add(i + 3, 2, "", xf);
                    if (temp[i].EmpName != null) sheet.Cells.Add(i + 3, 3, temp[i].EmpName.ToString(), xf); else sheet.Cells.Add(i + 3, 3, "", xf);
                    if (temp[i].CardNo != null) sheet.Cells.Add(i + 3, 4, temp[i].CardNo.ToString(), xf);
                    if (temp[i].Unit != null) sheet.Cells.Add(i + 3, 5, temp[i].Unit.ToString(), xf);

                    if (temp[i].Duty != null) sheet.Cells.Add(i + 3, 6, temp[i].Duty.ToString(), xf);

                    sheet.Cells.Add(i + 3, 7, temp[i].MianShiScore.ToString(), xf);
                    sheet.Cells.Add(i + 3, 8, temp[i].TotalScore.ToString(), xf);
                    sheet.Cells.Add(i + 3, 9, temp[i].NowDuty.ToString(), xf);
                    sheet.Cells.Add(i + 3, 10, temp[i].IsTongYi.ToString(), xf);
                }
                xls.Save(DataSheetExport);
                DataSheetExport.Close();
                DataSheetExport.Dispose();
                SilverlightMessageBoxLibrary.Message.InfoMessage("导出成功");
            }


        }
    }
}
